import { Component, OnInit ,ViewChild } from '@angular/core';
import { CommonService } from '../../service/common.service'
import { StorageService } from '../../service/storage.service'

@Component({
  selector: 'app-record',
  templateUrl: './record.page.html',
  styleUrls: ['./record.page.scss'],
})
export class RecordPage implements OnInit {
  @ViewChild('slides') slides;

  public czlist:any[] = [];
  public txlist:any[] = [];
  public zzlist:any[] = [];
  public page:number = 1
  public limit:number = 500
  public flag:boolean = false
  public segmentAModel:string = 's1';

  constructor(private storage:StorageService,private common:CommonService) { }

  

  ngOnInit() {
    this.czDetail()
    this.txDetail()
    this.zzDetail()
  }

  // 切换
  ontabs(value:any){
    let index:any;
    if(value == 's1'){
      index = 0
    }
    if(value == 's2'){
      index = 1
    }
    if(value == 's3'){
      index = 2
    }
    this.slides.slideTo(index,300)
  }

  // 滑动切换
  slideChange(){
    this.slides.getActiveIndex().then( Number =>{
      // console.log(Number)
      if(Number == 0){
        this.segmentAModel = 's1'
      }
      if(Number == 1){
        this.segmentAModel = 's2'
      }
      if(Number == 2){
        this.segmentAModel = 's3'
      }
    })
  }

  // 获取充值明细
  czDetail(){
    var api = '/tbr/queryOfflinePayDetail'
    var params = {
      userId:this.storage.get('PersonalInfo').userId,
      page:this.page,
      limit:this.limit
    }
    this.common.post(api,params,false).then((res:any)=>{
      console.log(res)
      if(res.code == 200){
        if(res.code == 200){
          for(var i=0;i<res.data.records.length;i++){
            this.czlist.push(res.data.records[i])
          }
          if(res.data.records.length < this.limit){
            this.flag = true
          }
        }
      }
    })
  }

  // 获取提现明细
  txDetail(){
    var api = '/tbr/withdrawadLogForUser'
    var params = {
      userId:this.common.getInfo().userId,
      page:this.page,
      limit:this.limit
    }
    // console.log(this.page)
    this.common.post(api,params,false).then((res:any)=>{
      if(res.code == 200){
        for(var i=0;i<res.data.records.length;i++){
          this.txlist.push(res.data.records[i])
        }
        if(res.data.records.length < this.limit){
          this.flag = true
        }
      }
    })
  }

  // 获取充值明细
  zzDetail(){
    var api = '/tbr/getTransferDetail'
    var params = {
      userId:this.common.getInfo().userId,
      page:this.page,
      limit:this.limit
    }
    console.log(this.page)
    this.common.post(api,params,false).then((res:any)=>{
      if(res.code == 200){
        for(var i=0;i<res.data.records.length;i++){
          this.zzlist.push(res.data.records[i])
        }
        if(res.data.records.length < this.limit){
          this.flag = true
        }
      }
    })
  }

  loadData(event){
      if (this.flag == true) {
        event.target.disabled = true;
        return
      }
    setTimeout(()=>{
      this.page += 1;
      this.txDetail()
      event.target.complete();
    },700)
  }

}
